# -*- coding: utf-8 -*-

# File Name： app
# Description :
# Author : Mark.Wei
# create_date： 2022/6/9
# Change Activity:

from typing import Dict, Any

from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware

from ml.micro_service.exception.ApiExceptionHandler import ApiExceptionHandler


class AppStarter:
    def __init__(self, params: Dict[str, Any]):
        self.instance = FastAPI(**params)

        self.instance.add_middleware(
            CORSMiddleware,
            allow_origins=["*"],
            allow_credentials=True,
            allow_methods=["*"],
            allow_headers=["*"],
        )

        ApiExceptionHandler(self.instance)
